//
//  ReportView_WX.m
//  ZITHER
//
//  Created by weixin on 2018/12/6.
//  Copyright © 2018 weixn. All rights reserved.
//

#import "ReportView_WX.h"
#import "ReportView_WX_Cell.h"

@implementation ReportView_WX

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self defaultConfiguration];
        self.index = 0;
    }
    return self;
}


-(void)defaultConfiguration{
    
    self.delegate = self;
    self.dataSource = self;
    
    /** 给头部间隙 */
//    self.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 20)];
    [self setLoad];
    
    //    @weakify(self);
    //    [RACObserve(self, page)subscribeNext:^(id  _Nullable x) {
    //        @strongify(self);
    //    }];
    
}
-(void)setLoad{
    [[serviceDefualt loadReportCategoryReponseObjctClass:nil]subscribeNext:^(ResponseData * x) {
        if (x.responseRawData) {
            
            self.arr = x.responseRawData[@"data"];
            
            [self reloadData];
            
        }else{
             [Tools showTips:x.errorInfo];
        }
    }];
}

#pragma MARK - 数据源
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count+1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    /* TODO: ================= 判断 cell 样式 =================*/
    
//    CoverCreateListModelSub *modelSub = self.model.result.list[indexPath.row];
    
        static NSString *sectionCell = @"ReportView_WX_Cell";
        ReportView_WX_Cell *cell = [tableView dequeueReusableCellWithIdentifier:sectionCell];
        if (cell == nil) {
            cell = [[ReportView_WX_Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
        }
    if (indexPath.row == 0) {
        cell.viewBorder.backgroundColor = [UIColor colorWithHex:@"dedede"];
        cell.reportType.hidden = YES;
        cell.reportTitle.hidden = NO;
    }else{
        cell.viewBorder.backgroundColor = [UIColor colorWithHex:@"eeeeee"];
        cell.reportType.hidden = NO;
        cell.reportTitle.hidden = YES;
        NSDictionary *dic = self.arr[indexPath.row-1];
        cell.reportType.text = dic[@"key"];
    }
    
    if (indexPath.row == self.index+1) {
        cell.pic.hidden = NO;
    }else{
        cell.pic.hidden = YES;
    }
        cell.selectionStyle = UITableViewCellSeparatorStyleNone;
//        cell.model = modelSub;
        return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row != 0) {
        self.index = indexPath.row -1;
        [self reloadData];
    }
   
}

@end
